package com.example.mvpdemo.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.View;

import com.example.mvpdemo.net.NetLoadingDialog;

public class BaseFragment extends Fragment implements View.OnClickListener, BaseView {

    private static final String TAG = "BaseFragment";
    /***
     * 加载dialog
     */
    private NetLoadingDialog mDialog;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        getView().setOnClickListener(this);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (mDialog == null) {
            mDialog = new NetLoadingDialog(context);
        }
    }

    @Override
    public void onClick(View v) {
        Log.e(TAG, "onClick -> " + v.getId());
    }

    /***
     * 显示dialog
     * @param text 显示内容
     * @param isClickCancle 点击是否取消
     */
    public void showDialog(String text, boolean isClickCancle) {
        if (mDialog != null) {
            mDialog.showDialog(text, isClickCancle);
        }
    }


    /***
     * 取消dialog
     */
    public void dismissDialog() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.closeDialog();
        }
    }


}
